1. Field of the Invention
The present invention relates to the processing of computer graphics, and in particular to an apparatus and method for processing graphics primitives in order to generate a scene for display.
2. Description of the Prior Art
When processing 3D graphics, a scene to be displayed is typically split into a number of basic components called “primitives” in order to allow the 3D graphics processing operations to be more readily carried out. The primitives are usually in the form of simple polygons, such as triangles.
Each primitive is typically defined by the vertices that make up the primitive, and each vertex will have associated with it particular data values representing the primitive at the vertex position, for example the X and Y position of the vertex, a depth (Z) value, colour and transparency values, etc. Within the graphics processing system, a primitive setup stage is performed that uses the data defined for each vertex of a given primitive in order to determine a plurality of functions for that primitive, such as edge functions that represent the geometric edges of the primitive, and a depth function used to determine a depth value at any particular point within the primitive. The primitive setup stage may also determine other functions such as interpolation functions that represent the way that the data values such as the colour values will vary across the primitive.
Following the primitive setup stage, a graphics primitive will be passed through a rasterization stage, where a rasterization operation is performed in order to determine a plurality of graphics fragments to be used to represent that graphics primitive, the rasterization operation determining the X and Y positions of each of those graphics fragments. Following rasterization, the graphics fragments are then passed through a rendering stage where the graphics fragments are subjected to colouring operations, shading operations, etc., in order to generate an output for display on a display screen.
Each graphics fragment (data element) may correspond to a single pixel (picture element) in the final display, or it can be the case that there is not a one-to-one correspondence between fragments and display pixels, for example where particular forms of post-processing such as down-scaling are carried out on the rendered image prior to displaying the final image.
In 3D graphics processing, rendering conceptually takes place within a so-called “view frustum”, which is, in effect, a box in front of the viewer's position which represents the three-dimensional volume within which primitives may need to be rendered for display. The view frustum is effectively defined by having top, left, bottom and right edge planes which define a viewport representing the edges of the view frustum, and near and far depth planes which represent the front and back planes of the view frustum (representing the closest and furthest distances at which objects can appear). The viewport typically corresponds to the size of the display screen.
It is typically desirable to only render the parts of the scene that will actually be seen, i.e. are within the view frustum, and one known technique to achieve this is to “clip” primitives against the view frustum edge and depth planes prior to performing the above-described primitive setup, rasterization and rendering processes. This often requires new primitives to be geometrically generated in order to represent the part of a primitive that remains within the view frustum after the clipping process. However, such a clipping process is fairly complex and slow, and difficult to implement.
As described in commonly-owned U.S. Pat. No. 8,115,783, the entire contents of which are hereby incorporated by reference, one known technique to try and reduce the amount of clipping required is referred to as “guard band clipping”. In guard band clipping, the edge planes against which primitives are tested for clipping purposes are extended to beyond (outside) the view frustum. Whilst in some guard band arrangements, the guard band is set to a finite value such as a defined number of pixels or fragments, in an alternative arrangement the clipping area edge planes are effectively set to “infinity”, thereby using an infinite guard band. Such an approach hence enables clipping to be avoided at the geometry processing stage (i.e. prior to rasterization and rendering), and instead additional steps can be taken later when processing the fragments to ensure that fragments outside the view frustum are not displayed.
When such an approach is taken in connection with the near and far depth planes of the view frustum, this means that rather than clipping primitives having vertices that are found to have depth values outside the valid depth range of the view frustum, those vertices are instead retained and those values are used when the primitive is rasterized into fragments. However, a depth bound clipping operation will later be required during processing of the graphics fragments, in order to discard graphics fragments whose associated depth value does not reside within the valid depth range of the view frustum.
However, many graphics Standards such as OpenGL and DirectX place constraints on the order in which certain processing steps must be performed. For example, both of the above Standards define that any depth bias process performed must be performed after the above depth bound clipping operation, but before the rendering process used to process the graphics fragments. Depth bias is the term used in the DirectX Standard, and the equivalent function in the OpenGL Standard is referred to as “depth offset” or “polygon offset”.
Depth bias is typically enabled or disabled on a draw call by draw call basis, and hence will be enabled or disabled in respect of all of the primitives that are the subject of a particular draw call. When depth bias is enabled for a draw call, this will ensure that if a first primitive that is included within that draw call has the same depth as a second primitive which is part of a draw call that does not have depth bias enabled, the first primitive will be reproduced so that it always appears on the surface of the second primitive irrespective of the viewing angle. This effect is achieved irrespective of the order in which the first and second primitives are processed.
As another example of an ordering constraint, the depth bound clipping operation will need to be performed before any early Z-processing stage is performed to determine whether a current fragment under consideration is nearer the viewer than any previously considered fragment at the same X, Y position.
It has been found that known approaches for conforming to these ordering constraints impacts the performance and/or the area of the graphics processing system, and accordingly it would be desirable to provide an improved mechanism for performing near/far depth bound clipping which reduces the impact on performance and/or area of the graphics processing system.